/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admintool.imp03_ui_components;

import admintool.AdminToolView;
import admintool.MatchRatingCalculator;
import admintool.imp03_data.IMP03_Candidate;
import admintool.imp03_data.IMP03_City;
import admintool.imp03_data.IMP03_Company;
import admintool.imp03_data.IMP03_Experience;
import admintool.imp03_data.IMP03_Gender;
import admintool.imp03_data.IMP03_Message;
import admintool.imp03_data.IMP03_Platform;
import admintool.imp03_data.IMP03_Qualification;
import admintool.imp03_data.IMP03_Skill;
import admintool.imp03_data.IMP03_Tip;
import admintool.imp03_data.IMP03_Vacancy;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Administrators
 */
public class SubSelectionListener implements ListSelectionListener{

    private javax.swing.JList list_subSelection;
    private javax.swing.JList list_mainSelection;
    private javax.swing.JPanel panel_parameters;
    private Connection dbConnection = null;
    
    private ArrayList<Object> myComponents = new ArrayList<Object>();
    
    private JComboBox platformVacancyComboBox = null;
    private JDialog platformVacancyDialog = null;

    private JComboBox skillLevelComboBox = null;

    private JComboBox skillVacancyComboBox = null;
    private JDialog skillVacancyDialog = null;

    private JComboBox tmpMessageCandidateComboBox = null;
    private JDialog messageCandidateDialog = null;

    private JComboBox skillCandidateComboBox = null;
    private JDialog skillCandidateDialog = null;

    private JComboBox platformCandidateComboBox = null;
    private JDialog platformCandidateDialog = null;

    private JDialog candidateExperienceDialog = null;
    private JTextField experience_CompanyName = null;
    private JTextField experience_RoleDesc = null;
    private JTextField experience_DurationInYears = null;
    
    private JLabel tmpLabel31 = null;
    private JComboBox tmpCombo3 = null;
    
    private JLabel tmpLabel41 = null;
    private JComboBox tmpCombo4 = null;

    private JLabel tmpLabel52 = null;
    private JComboBox tmpCombo51 = null;

    private JLabel tmpLabel72 = null;
    private JComboBox tmpCombo71 = null;
    
    private JLabel tmpLabel101 = null;
    private JComboBox tmpCombo10 = null;

    IMP03_Skill mainSelectionSkill = null;
    IMP03_Vacancy mainSelectionVacancy = null;
    IMP03_Candidate mainSelectionCandidate = null;
    
    JComboBox messageCandidateName = null;

    /**
     * 
     */
    public SubSelectionListener() {
    }
    
    /**
     * 
     * @param list_mainSelection
     * @param list_subSelection
     * @param panel_parameters
     * @param dbConnection
     */
    public SubSelectionListener(JList list_mainSelection, JList list_subSelection, JPanel panel_parameters, Connection dbConnection) {
        this.list_mainSelection = list_mainSelection;
        this.list_subSelection = list_subSelection;
        this.panel_parameters = panel_parameters;
        this.dbConnection = dbConnection;
    }

    public void valueChanged(ListSelectionEvent e) {
        if(!e.getValueIsAdjusting() && list_mainSelection.getSelectedValue() != null && list_subSelection.getSelectedValue() != null){
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                String mainSelection = list_mainSelection.getSelectedValue().toString();
                String subSelection = list_subSelection.getSelectedValue().toString();
                
                panel_parameters.removeAll();
                myComponents.clear();

                if (mainSelection.equalsIgnoreCase("PLATFORM")){
                    //// PLATFORM ////
                    IMP03_Platform platform = null;
                    if(subSelection.equalsIgnoreCase(AdminToolView.EMPTY)){
                        platform = IMP03_Platform.getEmptyPlatformObject();
                    } else {
                        platform = (IMP03_Platform) ((MyListModel)list_subSelection.getModel()).getMyCollection().getObject(subSelection);
                    }
                    
                    if(platform == null){
                        throw new Exception("IMP03_Platform could not be initialized");
                    }
                    
                    GroupLayout layout = new GroupLayout(panel_parameters);
                    layout.setAutoCreateGaps(true);
                    panel_parameters.setLayout(layout);

                    //JComponent definition
                    JLabel label1 = new JLabel("Name: ");
                    JLabel label2 = new JLabel("Desc: ");
                    JLabel label3 = new JLabel("Cost: ");
                    JLabel label4 = new JLabel("Vacancies: ");
                    JLabel label5 = new JLabel("Candidates: ");

                    JTextField text1 = new JTextField(platform.getPlatformName());
                    JTextArea text2 = new JTextArea(platform.getPlatformDesc());
                    JTextField text3 = new JTextField(String.valueOf(platform.getPlatformCost()));
                    text2.setLineWrap(true);
                    text2.setWrapStyleWord(true);
                    JScrollPane sp2 = new JScrollPane(text2);
                    JComboBox combo4 = new JComboBox(platform.getVacancyPlatforms().toArray());
                    combo4.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    JComboBox combo5 = new JComboBox(platform.getCandidatePlatforms().toArray());
                    combo5.setMaximumSize(new Dimension(1000, text1.getHeight()));

                    //array for the input components - DON'T CHANGE THE ORDERING!
                    myComponents.clear();
                    myComponents.add(platform);
                    myComponents.add(text1);
                    myComponents.add(text2);
                    myComponents.add(text3);
                    myComponents.add(combo4);
                    myComponents.add(combo5);

                    // declaration of buttons
                    JButton savePlatform = new JButton("Save \"" + text1.getText() + "\"-changes to the Database");
                    savePlatform.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(savePlatform()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton removePlatform = new JButton("Remove \"" + text1.getText() + "\" from the Database");
                    removePlatform.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(removeComponentFromDB()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton addVacancy = new JButton(" + ");
                    addVacancy.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addVacancyToPlatform()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removeVacancy = new JButton(" - ");
                    removeVacancy.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removeVacancyFromPlatform()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton addCandidate = new JButton(" + ");
                    addCandidate.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addPlatformToCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removeCandidate = new JButton(" - ");
                    removeCandidate.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removePlatformFromCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });                    

                    //disable buttons
                    if(platform.getPlatformName().equalsIgnoreCase(AdminToolView.EMPTY)){
                        removePlatform.setEnabled(false);
                        addVacancy.setEnabled(false);
                        removeVacancy.setEnabled(false);
                        addCandidate.setEnabled(false);
                        removeCandidate.setEnabled(false);
                    }
                    if(platform.getCandidatePlatforms().isEmpty()){
                        removeCandidate.setEnabled(false);
                    }
                    if(platform.getVacancyPlatforms().isEmpty()){
                        removeVacancy.setEnabled(false);
                    }
                    
                    // layout-definition
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(label1)
                                    .addComponent(label2)
                                    .addComponent(label3)
                                    .addComponent(label4)
                                    .addComponent(label5)
                                )
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(text1)
                                    .addComponent(sp2)
                                    .addComponent(text3)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(combo4)
                                        .addComponent(addVacancy)
                                        .addComponent(removeVacancy)
                                    )
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(combo5)
                                        .addComponent(addCandidate)
                                        .addComponent(removeCandidate)
                                    )
                                )
                            )
                            .addComponent(savePlatform, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removePlatform, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    );

                    layout.setVerticalGroup(
                        layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label1)
                                .addComponent(text1)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label2)
                                .addComponent(sp2)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label3)
                                .addComponent(text3)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label4)
                                .addComponent(combo4)
                                .addComponent(addVacancy)
                                .addComponent(removeVacancy)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label5)
                                .addComponent(combo5)
                                .addComponent(addCandidate)
                                .addComponent(removeCandidate)
                            )                            .addComponent(savePlatform)
                            .addComponent(removePlatform)
                    );
                } else if (mainSelection.equalsIgnoreCase("VACANCY")){
                    //// VACANCY ////
                    mainSelectionVacancy = null;
                    if(subSelection.equalsIgnoreCase(AdminToolView.EMPTY)){
                        mainSelectionVacancy = IMP03_Vacancy.getEmptyVacancyObject();                       
                    } else {
                        mainSelectionVacancy = (IMP03_Vacancy) ((MyListModel)list_subSelection.getModel()).getMyCollection().getObject(subSelection);
                    }
                    
                    if(mainSelectionVacancy == null){
                        throw new Exception("IMP03_Vacancy could not be initialized");
                    }
                    
                    GroupLayout layout = new GroupLayout(panel_parameters);
                    layout.setAutoCreateGaps(true);
                    panel_parameters.setLayout(layout);

                    //JComponent definitions
                    JLabel label1 = new JLabel("Title: ");
                    JLabel label2 = new JLabel("Desc: ");
                    JLabel label25 = new JLabel("Company: ");
                    JLabel label3 = new JLabel("PLZ: ");
                    JLabel label4 = new JLabel("StartDate [YYYY-MM-DD]: ");
                    JLabel label5 = new JLabel("Qualification: ");
                    JLabel label6 = new JLabel("Experience [Years]: ");
                    JLabel label7 = new JLabel("Budget [Euro]: ");
                    JLabel label8 = new JLabel("Anual Salary [Euro]: ");
                    JLabel label9 = new JLabel("FullTime: ");
                    JLabel label10 = new JLabel("Skills: ");
                    tmpLabel101 = new JLabel(AdminToolView.EMPTY);
                    JLabel label11 = new JLabel("Platforms: ");

                    JTextField text1 = new JTextField(mainSelectionVacancy.getVacancyTitle());
                    JTextField text2 = new JTextField(mainSelectionVacancy.getVacancyDesc());
                    
                    JComboBox combo25 = new JComboBox();
                    combo25.addItem(IMP03_Company.getEmptyCompanyObject());
                    for(IMP03_Company c : IMP03_Company.getAllAvailableCompaniesFromDB(true)){
                        combo25.addItem(c);
                        if(c.getName().equalsIgnoreCase(mainSelectionVacancy.getVacancyCompanyName())){
                            combo25.setSelectedItem(c);
                        }
                    }
                                        
                    tmpCombo51 = new JComboBox();
                    tmpCombo51.addItem(IMP03_City.getEmptyCityObject());
                    tmpLabel52 = new JLabel("");
                    for(IMP03_City c : IMP03_City.getAllAvailableCitiesFromDB(false)){
                        tmpCombo51.addItem(c);
                        if(c.getPLZ().equalsIgnoreCase(mainSelectionVacancy.getVacancyPLZ())){
                            tmpCombo51.setSelectedItem(c);
                            tmpLabel52.setText(c.getCityName());
                        }
                    }
                     tmpCombo51.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            tmpLabel52.setText(((IMP03_City)tmpCombo51.getSelectedItem()).getCityName());
                        }
                    });
                    tmpCombo51.setMaximumSize(new Dimension(100, tmpLabel52.getHeight()));
                    
                    JFormattedTextField date4 = new JFormattedTextField(new SimpleDateFormat("yyyy-mm-dd"));
                    date4.setText(String.valueOf(mainSelectionVacancy.getVacancyStartDate()));
                    JComboBox combo5 = new JComboBox();
                    combo5.addItem(IMP03_Qualification.getEmptyQualificationObject());
                    for(IMP03_Qualification q : IMP03_Qualification.getAllAvailableQualificationsFromDB(false)){
                        combo5.addItem(q);
                        if(q.getQualificationName().equalsIgnoreCase(mainSelectionVacancy.getVacancyQualification())){
                            combo5.setSelectedItem(q);
                        }
                    }
                    
                    JTextField text6 = new JTextField(String.valueOf(mainSelectionVacancy.getVacancyExperienceInYears()));
                    JTextField text7 = new JTextField(String.valueOf(mainSelectionVacancy.getVacancyBudget()));
                    JTextField text8 = new JTextField(String.valueOf(mainSelectionVacancy.getVacancyAnualSalary()));
                    JCheckBox check9 = new JCheckBox();
                    check9.setSelected(mainSelectionVacancy.isVacancyFullTimePartTime());

                    tmpCombo10 = new JComboBox(mainSelectionVacancy.getVacancySkills().toArray());
                    tmpCombo10.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    tmpCombo10.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            tmpLabel101.setText("SkillLevel: " + ((IMP03_Skill)(tmpCombo10.getSelectedItem())).getSkillLevelForVacancy(mainSelectionVacancy.getVacancyID()));
                        }
                    });
                    if(tmpCombo10.getItemCount() > 0){
                        tmpCombo10.setSelectedIndex(0);        
                    }
                    
                    
                    JComboBox combo11 = new JComboBox(mainSelectionVacancy.getVacancyPlatforms().toArray());
                    combo11.setMaximumSize(new Dimension(1000, text1.getHeight()));

                    
                    //array for the input components - DON'T CHANGE THE ORDERING!
                    myComponents.clear();
                    myComponents.add(mainSelectionVacancy);
                    myComponents.add(text1);
                    myComponents.add(text2);
                    myComponents.add(combo25);
                    myComponents.add(tmpCombo51);
                    myComponents.add(date4);
                    myComponents.add(combo5);
                    myComponents.add(text6);
                    myComponents.add(text7);
                    myComponents.add(text8);
                    myComponents.add(check9);
                    myComponents.add(tmpCombo10);
                    myComponents.add(combo11);

                    //Buttons
                    JButton saveVacancy = new JButton("Save \"" + text1.getText() + "\"-changes to the Database");
                    saveVacancy.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(saveVacancy()){
                                updateCandidateVacancyMatch();
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton removeVacancy = new JButton("Remove \"" + text1.getText() + "\" from the Database");
                    removeVacancy.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(removeComponentFromDB()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton addPlatform = new JButton(" + ");
                    addPlatform.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addVacancyToPlatform()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removePlatform = new JButton(" - ");
                    removePlatform.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removeVacancyFromPlatform()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });    
                    
                    JButton addSkill = new JButton(" + ");
                    addSkill.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addSkillToVacancy()){
                                updateCandidateVacancyMatch();
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removeSkill = new JButton(" - ");
                    removeSkill.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removeSkillFromVacancy()){
                                updateCandidateVacancyMatch();
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });                    
                    
                    
                    //disable buttons
                    if(mainSelectionVacancy.getVacancyTitle().equalsIgnoreCase(AdminToolView.EMPTY)){
                        removeVacancy.setEnabled(false);
                        addPlatform.setEnabled(false);
                        removePlatform.setEnabled(false);
                        addSkill.setEnabled(false);
                        removeSkill.setEnabled(false);
                    }
                    
                    if(mainSelectionVacancy.getVacancyPlatforms().isEmpty()){
                        removePlatform.setEnabled(false);
                    }
                    
                    if(mainSelectionVacancy.getVacancySkills().isEmpty()){
                        removeSkill.setEnabled(false);
                    }

                    //define layout
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(label1)
                                    .addComponent(label2)
                                    .addComponent(label25)
                                    .addComponent(label3)
                                    .addComponent(label4)
                                    .addComponent(label5)
                                    .addComponent(label6)
                                    .addComponent(label7)
                                    .addComponent(label8)
                                    .addComponent(label9)
                                    .addComponent(label10)
                                    .addComponent(label11)
                            )
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(text1)
                                    .addComponent(text2)
                                    .addComponent(combo25)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tmpCombo51)
                                        .addComponent(tmpLabel52)
                                    )
                                    .addComponent(date4)
                                    .addComponent(combo5)
                                    .addComponent(text6)
                                    .addComponent(text7)
                                    .addComponent(text8)
                                    .addComponent(check9)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tmpCombo10)
                                        .addComponent(tmpLabel101)
                                        .addComponent(addSkill)
                                        .addComponent(removeSkill)
                                    )
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(combo11)
                                        .addComponent(addPlatform)
                                        .addComponent(removePlatform)
                                    )
                                )
                            )
                            .addComponent(saveVacancy, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removeVacancy, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    );

                    layout.setVerticalGroup(
                        layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label1)
                                .addComponent(text1)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label2)
                                .addComponent(text2)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label25)
                                .addComponent(combo25)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label3)
                                .addComponent(tmpCombo51)
                                .addComponent(tmpLabel52)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label4)
                                .addComponent(date4)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label5)
                                .addComponent(combo5)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label6)
                                .addComponent(text6)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label7)
                                .addComponent(text7)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label8)
                                .addComponent(text8)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label9)
                                .addComponent(check9)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label10)
                                .addComponent(tmpCombo10)
                                .addComponent(tmpLabel101)
                                .addComponent(addSkill)
                                .addComponent(removeSkill)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label11)
                                .addComponent(combo11)
                                .addComponent(addPlatform)
                                .addComponent(removePlatform)
                            )
                            .addComponent(saveVacancy)
                            .addComponent(removeVacancy)
                    );
                } else if (mainSelection.equalsIgnoreCase("COMPANY")){
                    //// COMPANY ////
                    IMP03_Company company = null;
                    if(subSelection.equalsIgnoreCase(AdminToolView.EMPTY)){
                        company = IMP03_Company.getEmptyCompanyObject();
                    } else {
                        company = (IMP03_Company) ((MyListModel)list_subSelection.getModel()).getMyCollection().getObject(subSelection);
                    }
                    
                    if(company == null){
                        throw new Exception("IMP03_Company could not be initialized");
                    }
                    
                    GroupLayout layout = new GroupLayout(panel_parameters);
                    layout.setAutoCreateGaps(true);
                    panel_parameters.setLayout(layout);

                    //JComponent definition
                    JLabel label1 = new JLabel("Name: ");
                    JLabel label2 = new JLabel("Branch: ");
                    JLabel label3 = new JLabel("Size: ");
                    JLabel label4 = new JLabel("Revenue [Euro]: ");
                    JLabel label5 = new JLabel("Comment: ");

                    JTextField text1 = new JTextField(company.getName());
                    JTextField text2 = new JTextField(company.getBranch());
                    JTextField text3 = new JTextField(String.valueOf(company.getSize()));
                    JTextField text4 = new JTextField(String.valueOf(company.getRevenue()));
                    JTextField text5 = new JTextField(company.getComment());

                    text2.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    text3.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    text4.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    text5.setMaximumSize(new Dimension(1000, text1.getHeight()));

                    //array for the input components - DON'T CHANGE THE ORDERING!
                    myComponents.clear();
                    myComponents.add(company);
                    myComponents.add(text1);
                    myComponents.add(text2);
                    myComponents.add(text3);
                    myComponents.add(text4);
                    myComponents.add(text5);

                    // declaration of buttons
                    JButton saveCompany = new JButton("Save \"" + text1.getText() + "\"-changes to the Database");
                    saveCompany.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(saveCompany()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton removeCompany = new JButton("Remove \"" + text1.getText() + "\" from the Database");
                    removeCompany.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(removeComponentFromDB()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    //disable buttons
                    if(company.getName().equalsIgnoreCase(AdminToolView.EMPTY)){
                        removeCompany.setEnabled(false);
                    }
                    
                    // layout-definition
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(label1)
                                    .addComponent(label2)
                                    .addComponent(label3)
                                    .addComponent(label4)
                                    .addComponent(label5)
                                )
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(text1)
                                    .addComponent(text2)
                                    .addComponent(text3)
                                    .addComponent(text4)
                                    .addComponent(text5)
                                )
                            )
                            .addComponent(saveCompany, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removeCompany, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    );

                    layout.setVerticalGroup(
                        layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label1)
                                .addComponent(text1)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label2)
                                .addComponent(text2)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label3)
                                .addComponent(text3)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label4)
                                .addComponent(text4)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label5)
                                .addComponent(text5)
                            )
                            .addComponent(saveCompany)
                            .addComponent(removeCompany)
                    );
                } else if (mainSelection.equalsIgnoreCase("SKILL")){
                    //// SKILL////
                    mainSelectionSkill = null;
                    if(subSelection.equalsIgnoreCase(AdminToolView.EMPTY)){
                        mainSelectionSkill = IMP03_Skill.getEmptySkillObject();
                    } else {
                        mainSelectionSkill = (IMP03_Skill) ((MyListModel)list_subSelection.getModel()).getMyCollection().getObject(subSelection);
                    }
                    
                    if(mainSelectionSkill == null){
                        throw new Exception("IMP03_Skill could not be initialized");
                    }
                    
                    GroupLayout layout = new GroupLayout(panel_parameters);
                    layout.setAutoCreateGaps(true);
                    panel_parameters.setLayout(layout);

                    //JComponent definition
                    JLabel label1 = new JLabel("Name: ");
                    JLabel label2 = new JLabel("Desc: ");
                    JLabel label3 = new JLabel("Vacancies: ");
                    JLabel label4 = new JLabel("Candidates: ");
                    tmpLabel31 = new JLabel(AdminToolView.EMPTY);
                    tmpLabel41 = new JLabel(AdminToolView.EMPTY);

                    JTextField text1 = new JTextField(mainSelectionSkill.getSkillName());
                    JTextField text2 = new JTextField(mainSelectionSkill.getSkillDesc());
                    text2.setMaximumSize(new Dimension(1000, text1.getHeight()));

                    tmpCombo3 = new JComboBox(mainSelectionSkill.getVacancySkills().toArray());
                    tmpCombo3.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    tmpCombo3.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            tmpLabel31.setText("SkillLevel: " + ((IMP03_Vacancy)(tmpCombo3.getSelectedItem())).getSkillLevelForVacancy(mainSelectionSkill.getSkillID()));
                        }
                    });
                    if(tmpCombo3.getItemCount() > 0){
                        tmpCombo3.setSelectedIndex(0);
                    }
                    
                    tmpCombo4 = new JComboBox(mainSelectionSkill.getCandidateSkills().toArray());
                    tmpCombo4.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    tmpCombo4.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            tmpLabel41.setText("SkillLevel: " + ((IMP03_Candidate)(tmpCombo4.getSelectedItem())).getSkillLevelForCandidate(mainSelectionSkill.getSkillID()));
                        }
                    });
                    if(tmpCombo4.getItemCount() > 0){
                        tmpCombo4.setSelectedIndex(0);
                    }

                    //array for the input components - DON'T CHANGE THE ORDERING!
                    myComponents.clear();
                    myComponents.add(mainSelectionSkill);
                    myComponents.add(text1);
                    myComponents.add(text2);
                    myComponents.add(tmpCombo3);
                    myComponents.add(tmpCombo4);

                    // declaration of buttons
                    JButton saveSkill = new JButton("Save \"" + text1.getText() + "\"-changes to the Database");
                    saveSkill.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(saveSkill()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton removeSkill = new JButton("Remove \"" + text1.getText() + "\" from the Database");
                    removeSkill.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(removeComponentFromDB()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton addVacancy = new JButton(" + ");
                    addVacancy.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addSkillToVacancy()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removeVacancy = new JButton(" - ");
                    removeVacancy.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removeSkillFromVacancy()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });                    

                    JButton addCandidate = new JButton(" + ");
                    addCandidate.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addSkillToCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removeCandidate = new JButton(" - ");
                    removeCandidate.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removeSkillFromCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });                    
                    
                    //disable buttons
                    if(mainSelectionSkill.getSkillName().equalsIgnoreCase(AdminToolView.EMPTY)){
                        removeSkill.setEnabled(false);
                        addVacancy.setEnabled(false);
                        removeVacancy.setEnabled(false);
                        addCandidate.setEnabled(false);
                        removeCandidate.setEnabled(false);
                    }
                    
                    if(mainSelectionSkill.getCandidateSkills().isEmpty()){
                        removeCandidate.setEnabled(false);
                    }
                    if(mainSelectionSkill.getVacancySkills().isEmpty()){
                        removeVacancy.setEnabled(false);
                    }
                    
                    // layout-definition
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(label1)
                                    .addComponent(label2)
                                    .addComponent(label3)
                                    .addComponent(label4)
                                )
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(text1)
                                    .addComponent(text2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tmpCombo3)
                                        .addComponent(tmpLabel31)
                                        .addComponent(addVacancy)
                                        .addComponent(removeVacancy)
                                    )
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tmpCombo4)
                                        .addComponent(tmpLabel41)
                                        .addComponent(addCandidate)
                                        .addComponent(removeCandidate)
                                    )
                                )
                            )
                            .addComponent(saveSkill, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removeSkill, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    );

                    layout.setVerticalGroup(
                        layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label1)
                                .addComponent(text1)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label2)
                                .addComponent(text2)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label3)
                                .addComponent(tmpCombo3)
                                .addComponent(tmpLabel31)
                                .addComponent(addVacancy)
                                .addComponent(removeVacancy)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label4)
                                .addComponent(tmpCombo4)
                                .addComponent(tmpLabel41)
                                .addComponent(addCandidate)
                                .addComponent(removeCandidate)
                            )
                            .addComponent(saveSkill)
                            .addComponent(removeSkill)
                    );
                } else if (mainSelection.equalsIgnoreCase("CANDIDATE")){
                    //// CANDIDATE ////
                    mainSelectionCandidate = null;
                    if(subSelection.equalsIgnoreCase(AdminToolView.EMPTY)){
                        mainSelectionCandidate = IMP03_Candidate.getEmptyCandidateObject();
                    } else {
                        mainSelectionCandidate = (IMP03_Candidate) ((MyListModel)list_subSelection.getModel()).getMyCollection().getObject(subSelection);
                    }
                    
                    if(mainSelectionCandidate == null){
                        throw new Exception("IMP03_Candidate could not be initialized");
                    }
                    
                    GroupLayout layout = new GroupLayout(panel_parameters);
                    layout.setAutoCreateGaps(true);
                    panel_parameters.setLayout(layout);

                    //JComponent definition
                    JLabel label1 = new JLabel("Last name: ");
                    JLabel label2 = new JLabel("First name: ");
                    JLabel label3 = new JLabel("Gender: ");
                    JLabel label4 = new JLabel("Date of birth [YYYY-MM-DD]: ");
                    JLabel label5 = new JLabel("PLZ: ");
                    JLabel label6 = new JLabel("Qualification: ");
                    JLabel label7 = new JLabel("Skills: ");
                    tmpLabel72 = new JLabel(AdminToolView.EMPTY);
                    JLabel label8 = new JLabel("Platforms: ");
                    JLabel label9 = new JLabel("Experience: ");

                    JTextField text1 = new JTextField(mainSelectionCandidate.getLastName());
                    JTextField text2 = new JTextField(mainSelectionCandidate.getFirstName());
                    JComboBox combo3 = new JComboBox();
                    combo3.addItem(IMP03_Gender.getEmptyGenderObject());
                    for(IMP03_Gender g : IMP03_Gender.getAllAvailableGendersFromDB(false)){
                        combo3.addItem(g);
                        if(g.getGenderName().equalsIgnoreCase(mainSelectionCandidate.getGender())){
                            combo3.setSelectedItem(g);
                        }
                    }
                    JFormattedTextField date4 = new JFormattedTextField(new SimpleDateFormat("yyyy-mm-dd"));
                    date4.setText(String.valueOf(mainSelectionCandidate.getDateOfBirth()));
                    tmpCombo51 = new JComboBox();
                    tmpCombo51.addItem(IMP03_City.getEmptyCityObject());
                    tmpLabel52 = new JLabel("");
                    for(IMP03_City c : IMP03_City.getAllAvailableCitiesFromDB(false)){
                        tmpCombo51.addItem(c);
                        if(c.getPLZ().equalsIgnoreCase(mainSelectionCandidate.getPLZ())){
                            tmpCombo51.setSelectedItem(c);
                            tmpLabel52.setText(c.getCityName());
                        }
                    }
                     tmpCombo51.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            tmpLabel52.setText(((IMP03_City)tmpCombo51.getSelectedItem()).getCityName());
                        }
                    });
                    tmpCombo51.setMaximumSize(new Dimension(100, tmpLabel52.getHeight()));

                    JComboBox combo6 = new JComboBox();
                    combo6.addItem(IMP03_Qualification.getEmptyQualificationObject());
                    for(IMP03_Qualification q : IMP03_Qualification.getAllAvailableQualificationsFromDB(false)){
                        combo6.addItem(q);
                        if(q.getQualificationName().equalsIgnoreCase(mainSelectionCandidate.getQualification())){
                            combo6.setSelectedItem(q);
                        }
                    }
                    tmpCombo71 = new JComboBox(mainSelectionCandidate.getCandidateSkills().toArray());
                    tmpCombo71.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            tmpLabel72.setText("SkillLevel: " + ((IMP03_Skill)(tmpCombo71.getSelectedItem())).getSkillLevelForCandidate(mainSelectionCandidate.getCandidateID()));
                        }
                    });                    
                    if(tmpCombo71.getItemCount() > 0){
                        tmpCombo71.setSelectedIndex(0);
                    }
                    
                    JComboBox combo8 = new JComboBox(mainSelectionCandidate.getCandidatePlatforms().toArray());

                    JComboBox combo9 = new JComboBox(mainSelectionCandidate.getCandidateExperience().toArray());
                    
                    
                    text2.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    combo3.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    date4.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    combo6.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    tmpCombo71.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    combo8.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    combo9.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    
                    
                    //array for the input components - DON'T CHANGE THE ORDERING!
                    myComponents.clear();
                    myComponents.add(mainSelectionCandidate);
                    myComponents.add(text1);
                    myComponents.add(text2);
                    myComponents.add(combo3);
                    myComponents.add(date4);
                    myComponents.add(tmpCombo51);
                    myComponents.add(combo6);
                    myComponents.add(tmpCombo71);
                    myComponents.add(combo8);
                    myComponents.add(combo9);

                    // declaration of buttons
                    JButton saveCandidate = new JButton("Save \"" + text1.getText() + "\"-changes to the Database");
                    saveCandidate.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(saveCandidate()){
                                updateCandidateVacancyMatch();
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton removeCandidate = new JButton("Remove \"" + text1.getText() + "\" from the Database");
                    removeCandidate.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(removeComponentFromDB()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton addSkill = new JButton(" + ");
                    addSkill.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addSkillToCandidate()){
                                updateCandidateVacancyMatch();
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removeSkill = new JButton(" - ");
                    removeSkill.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removeSkillFromCandidate()){
                                updateCandidateVacancyMatch();
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });                 
                    
                    JButton addPlatform = new JButton(" + ");
                    addPlatform.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addPlatformToCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removePlatform = new JButton(" - ");
                    removePlatform.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removePlatformFromCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });                      

                    JButton addExperience = new JButton(" + ");
                    addExperience.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(addExperienceToCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    JButton removeExperience = new JButton(" - ");
                    removeExperience.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            if(removeExperienceFromCandidate()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });                        
                    
                    //disable buttons
                    if(mainSelectionCandidate.getLastName().equalsIgnoreCase(AdminToolView.EMPTY)){
                        removeCandidate.setEnabled(false);
                        addSkill.setEnabled(false);
                        removeSkill.setEnabled(false);
                        addPlatform.setEnabled(false);
                        removePlatform.setEnabled(false);
                        addExperience.setEnabled(false);
                        removeExperience.setEnabled(false);
                    }
                    
                    if(mainSelectionCandidate.getCandidatePlatforms().isEmpty()){
                        removePlatform.setEnabled(false);
                    }
                    if(mainSelectionCandidate.getCandidateSkills().isEmpty()){
                        removeSkill.setEnabled(false);
                    }
                    if(mainSelectionCandidate.getCandidateExperience().isEmpty()){
                        removeExperience.setEnabled(false);
                    }
                    
                    // layout-definition
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(label1)
                                    .addComponent(label2)
                                    .addComponent(label3)
                                    .addComponent(label4)
                                    .addComponent(label5)
                                    .addComponent(label6)
                                    .addComponent(label7)
                                    .addComponent(label8)
                                    .addComponent(label9)
                                )
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(text1)
                                    .addComponent(text2)
                                    .addComponent(combo3)
                                    .addComponent(date4)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tmpCombo51)
                                        .addComponent(tmpLabel52)
                                    )        
                                    .addComponent(combo6)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tmpCombo71)
                                        .addComponent(tmpLabel72)
                                        .addComponent(addSkill)
                                        .addComponent(removeSkill)
                                    )        
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(combo8)
                                        .addComponent(addPlatform)
                                        .addComponent(removePlatform)
                                    )        
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(combo9)
                                        .addComponent(addExperience)
                                        .addComponent(removeExperience)
                                    )        
                                )
                            )
                            .addComponent(saveCandidate, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removeCandidate, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    );

                    layout.setVerticalGroup(
                        layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label1)
                                .addComponent(text1)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label2)
                                .addComponent(text2)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label3)
                                .addComponent(combo3)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label4)
                                .addComponent(date4)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label5)
                                .addComponent(tmpCombo51)
                                .addComponent(tmpLabel52)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label6)
                                .addComponent(combo6)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label7)
                                .addComponent(tmpCombo71)
                                .addComponent(tmpLabel72)
                                .addComponent(addSkill)
                                .addComponent(removeSkill)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label8)
                                .addComponent(combo8)
                                .addComponent(addPlatform)
                                .addComponent(removePlatform)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                .addComponent(label9)
                                .addComponent(combo9)
                                .addComponent(addExperience)
                                .addComponent(removeExperience)
                            )
                            .addComponent(saveCandidate)
                            .addComponent(removeCandidate)
                    );
                } else if (mainSelection.equalsIgnoreCase("MESSAGE")){
                    //// MESSAGE ////
                    IMP03_Message message = null;
                    if(subSelection.equalsIgnoreCase(AdminToolView.EMPTY)){
                        message = IMP03_Message.getEmptyMessageObject();
                    } else {
                        message = (IMP03_Message) ((MyListModel)list_subSelection.getModel()).getMyCollection().getObject(subSelection);
                    }
                    
                    if(message == null){
                        throw new Exception("IMP03_Message could not be initialized");
                    }
                    
                    GroupLayout layout = new GroupLayout(panel_parameters);
                    layout.setAutoCreateGaps(true);
                    panel_parameters.setLayout(layout);

                    //JComponent definition
                    JLabel label1 = new JLabel("Subject: ");
                    JLabel label2 = new JLabel("Content: ");
                    JLabel label3 = new JLabel("Candidate: ");

                    JTextField text1 = new JTextField(message.getMessageSubject());
                    JTextArea text2 = new JTextArea(message.getMessageContent());
                    text2.setLineWrap(true);
                    text2.setWrapStyleWord(true);
                    JScrollPane sp2 = new JScrollPane(text2);
                    messageCandidateName = new JComboBox(new Object[]{(Object)IMP03_Candidate.getSpecificCandidateFromDB(message.getMessageCandidateID())});
                    messageCandidateName.setEnabled(false);

                    //array for the input components - DON'T CHANGE THE ORDERING!
                    myComponents.clear();
                    myComponents.add(message);
                    myComponents.add(text1);
                    myComponents.add(text2);
                    myComponents.add(messageCandidateName);

                    // declaration of buttons
                    JButton saveMessage = new JButton("Save \"" + text1.getText() + "\"-changes to the Database");
                    saveMessage.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(saveMessage()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton removeMessage = new JButton("Remove \"" + text1.getText() + "\" from the Database");
                    removeMessage.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(removeComponentFromDB()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton changeCandidate = new JButton("change candidate");
                    changeCandidate.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            addCandidateToMessage();
                        }
                    });
             

                    //disable buttons
                    if(message.getMessageSubject().equalsIgnoreCase(AdminToolView.EMPTY)){
                        removeMessage.setEnabled(false);
                    }
                    
                    // layout-definition
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(label1)
                                    .addComponent(label2)
                                    .addComponent(label3)
                                )
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(text1)
                                    .addComponent(sp2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(messageCandidateName)
                                        .addComponent(changeCandidate)
                                    )
                                )
                            )
                            .addComponent(saveMessage, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removeMessage, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    );

                    layout.setVerticalGroup(
                        layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label1)
                                .addComponent(text1)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label2)
                                .addComponent(sp2)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label3)
                                .addComponent(messageCandidateName)
                                .addComponent(changeCandidate)
                            )
                            .addComponent(saveMessage)
                            .addComponent(removeMessage)
                    );
                } else if (mainSelection.equalsIgnoreCase("TIP")){
                    //// TIP ////
                    IMP03_Tip tip = null;
                    if(subSelection.equalsIgnoreCase(AdminToolView.EMPTY)){
                        tip = IMP03_Tip.getEmptyTipObject();
                    } else {
                        tip = (IMP03_Tip) ((MyListModel)list_subSelection.getModel()).getMyCollection().getObject(subSelection);
                    }
                    
                    if(tip == null){
                        throw new Exception("IMP03_Tip could not be initialized");
                    }
                    
                    GroupLayout layout = new GroupLayout(panel_parameters);
                    layout.setAutoCreateGaps(true);
                    panel_parameters.setLayout(layout);

                    //JComponent definition
                    JLabel label1 = new JLabel("StageID: ");
                    JLabel label2 = new JLabel("Costs: ");
                    JLabel label3 = new JLabel("Text: ");

                    JTextField text1 = new JTextField(String.valueOf(tip.getStageID()));
                    JTextField text2 = new JTextField(String.valueOf(tip.getCosts()));
                    JTextArea text3 = new JTextArea(tip.getTipText());
                    text3.setLineWrap(true);
                    text3.setWrapStyleWord(true);
                    JScrollPane sp3 = new JScrollPane(text3);
                    
                    //array for the input components - DON'T CHANGE THE ORDERING!
                    myComponents.clear();
                    myComponents.add(tip);
                    myComponents.add(text1);
                    myComponents.add(text2);
                    myComponents.add(text3);

                    // declaration of buttons
                    JButton saveTip = new JButton("Save Stage No. #" + text1.getText() + " tip to the Database");
                    saveTip.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(saveTip()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });
                    
                    JButton removeTip = new JButton("Remove Stage No. #" + text1.getText() + " tip from the Database");
                    removeTip.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if(removeComponentFromDB()){
                                MainSelectionListener msl = new MainSelectionListener(list_mainSelection, list_subSelection, panel_parameters, dbConnection);
                                msl.valueChanged(new ListSelectionEvent(e, 0, 0, false));
                            }
                        }
                    });

                    //disable buttons
                    if(tip.getTipText().equalsIgnoreCase(AdminToolView.EMPTY)){
                        removeTip.setEnabled(false);
                    }
                    
                    // layout-definition
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(label1)
                                    .addComponent(label2)
                                    .addComponent(label3)
                                )
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(text1)
                                    .addComponent(text2)
                                    .addComponent(sp3)
                                )
                            )
                            .addComponent(saveTip, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removeTip, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    );

                    layout.setVerticalGroup(
                        layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label1)
                                .addComponent(text1)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label2)
                                .addComponent(text2)
                            )
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(label3)
                                .addComponent(sp3)
                            )
                            .addComponent(saveTip)
                            .addComponent(removeTip)
                    );
                }
            } catch (Exception e1) {
                e1.printStackTrace();
            } finally {
                try {
                    if(rs != null){
                        rs.close();
                    }
                    if(ps != null){
                        ps.close();
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        }
    }


    private boolean removeComponentFromDB(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Platform platform = null;
            IMP03_Vacancy vacancy = null;
            IMP03_Company company = null;
            IMP03_Skill skill = null;
            IMP03_Candidate candidate = null;
            IMP03_Message message = null;
            IMP03_Tip tip = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Platform){
                    platform = (IMP03_Platform) obj;
                    break;
                } else if(obj instanceof IMP03_Vacancy){
                    vacancy = (IMP03_Vacancy) obj;
                    break;
                } else if(obj instanceof IMP03_Company){
                    company = (IMP03_Company) obj;
                } else if(obj instanceof IMP03_Skill){
                    skill = (IMP03_Skill) obj;
                } else if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                } else if(obj instanceof IMP03_Message){
                    message = (IMP03_Message) obj;
                } else if(obj instanceof IMP03_Tip){
                    tip = (IMP03_Tip) obj;
                }
            }
            
            if(platform == null && vacancy == null && company == null && skill == null && candidate == null && message == null && tip == null){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }
            
            if(platform != null){
                int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the platform from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(result == 0){
                    ps = dbConnection.prepareStatement("DELETE FROM platform WHERE PlatformId = ?");
                    ps.setInt(1, platform.getPlatformID());
                    ps.executeUpdate();

                    returnValue = true;
                    JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                }
            } else if(vacancy != null){
                int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the vacancy from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(result == 0){
                    ps = dbConnection.prepareStatement("DELETE FROM vacancy WHERE VacancyId = ?");
                    ps.setInt(1, vacancy.getVacancyID());
                    ps.executeUpdate();

                    returnValue = true;
                    JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                }
            } else if(company != null){
                int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the company from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(result == 0){
                    ps = dbConnection.prepareStatement("DELETE FROM company WHERE CompanyID = ?");
                    ps.setInt(1, company.getCompanyID());
                    ps.executeUpdate();

                    returnValue = true;
                    JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                }
            } else if(skill != null){
                int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the skill from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(result == 0){
                    ps = dbConnection.prepareStatement("DELETE FROM skill WHERE SkillID = ?");
                    ps.setInt(1, skill.getSkillID());
                    ps.executeUpdate();

                    returnValue = true;
                    JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                }
            } else if(candidate != null){
                int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the skill from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(result == 0){
                    ps = dbConnection.prepareStatement("DELETE FROM candidate WHERE CandidateID = ?");
                    ps.setInt(1, candidate.getCandidateID());
                    ps.executeUpdate();

                    returnValue = true;
                    JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                }
            } else if(message != null){
                int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the message from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(result == 0){
                    ps = dbConnection.prepareStatement("DELETE FROM message WHERE MessageID = ?");
                    ps.setInt(1, message.getMessageID());
                    ps.executeUpdate();

                    returnValue = true;
                    JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                }
            } else if(tip != null){
                int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the tip from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(result == 0){
                    ps = dbConnection.prepareStatement("DELETE FROM tip WHERE TipID = ?");
                    ps.setInt(1, tip.getTipID());
                    ps.executeUpdate();

                    returnValue = true;
                    JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                }
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }
    
    private boolean saveCandidate(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            int counter = 0;
            IMP03_Candidate candidate = null;
            String lastName = "";
            String firstName = "";
            int gender = 0;
            Date dateOfBirth = null;
            String plz = "";
            int qualification = 0;
        
            for(Object obj : myComponents){
                if(counter == 0 && obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                } else if(counter == 1 && obj instanceof JTextField /*&& isValid(obj)*/){
                    lastName = ((JTextField)obj).getText();
                    
                    if(lastName.equalsIgnoreCase(AdminToolView.EMPTY) || lastName.equalsIgnoreCase("")){
                        throw new Exception("ERROR: Attemp to upload empty data to the database!");
                    }
                } else if(counter == 2 && obj instanceof JTextField && isValid(obj)){
                    firstName = ((JTextField)obj).getText();
                } else if(counter == 3 && obj instanceof JComboBox && isValid(obj)){
                    gender = ((IMP03_Gender)(((JComboBox)obj).getSelectedItem())).getGenderID();
                } else if(counter == 4 && obj instanceof JFormattedTextField && isValid(obj)){
                    String date = ((JFormattedTextField)obj).getText();
                    Pattern myPattern = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}");
                    Matcher m = myPattern.matcher(date);
                    if(m.matches()){
                        dateOfBirth = Date.valueOf(date);
                    }                    
                } else if(counter == 5 && obj instanceof JComboBox && isValid(obj)){
                    plz = ((JComboBox)obj).getSelectedItem().toString();
                } else if(counter == 6 && obj instanceof JComboBox && isValid(obj)){
                    qualification = ((IMP03_Qualification)(((JComboBox)obj).getSelectedItem())).getQualificationID();
                }
                counter++;
            }
                        
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you want to update the Database?", "DB Upload", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(candidate.getCandidateID() == -1){
                    ps = dbConnection.prepareStatement("INSERT INTO candidate (LastName, FirstName, PLZ, GenderID, DateOfBirth, QualificationID) VALUES (?, ?, ?, ?, ?, ?)");
                    ps.setString(1, lastName);
                    ps.setString(2, firstName);
                    ps.setString(3, plz);
                    ps.setInt(4, gender);
                    ps.setDate(5, dateOfBirth);
                    ps.setInt(6, qualification);
                } else {
                    ps = dbConnection.prepareStatement("UPDATE candidate SET LastName = ?, FirstName = ?, PLZ = ?, GenderID = ?, DateOfBirth = ?, QualificationID = ? WHERE CandidateId = ?");
                    ps.setString(1, lastName);
                    ps.setString(2, firstName);
                    ps.setString(3, plz);
                    ps.setInt(4, gender);
                    ps.setDate(5, dateOfBirth);
                    ps.setInt(6, qualification);
                    ps.setInt(7, candidate.getCandidateID());
                }
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Upload to the Database successful", "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }
    
    private boolean savePlatform(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            int counter = 0;
            IMP03_Platform platform = null;
            String newPlatformName = null;
            String newPlatformDesc = null;
            int newPlatformCost = 0;
            
            for(Object obj : myComponents){
                if(counter == 0 && obj instanceof IMP03_Platform){
                    platform = (IMP03_Platform) obj;
                } else if(counter == 1 && obj instanceof JTextField /*&& isValid(obj)*/){
                    newPlatformName = ((JTextField)obj).getText();
                    
                    if(newPlatformName.equalsIgnoreCase(AdminToolView.EMPTY) || newPlatformName.equalsIgnoreCase("")){
                        throw new Exception("ERROR: Attemp to upload empty data to the database!");
                    }
                } else if(counter == 2 && obj instanceof JTextArea && isValid(obj)){
                    newPlatformDesc = ((JTextArea)obj).getText();
                } else if(counter == 3 && obj instanceof JTextField && isValid(obj)){
                    newPlatformCost = Integer.parseInt(((JTextField)obj).getText());
                }
                counter++;
            }
                        
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you want to update the Database?", "DB Upload", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(platform.getPlatformID() == -1){
                    ps = dbConnection.prepareStatement("INSERT INTO platform (Name, Description, Cost) VALUES (?, ?, ?)");
                    ps.setString(1, newPlatformName);
                    ps.setString(2, newPlatformDesc);
                    ps.setInt(3, newPlatformCost);
                } else {
                    ps = dbConnection.prepareStatement("UPDATE platform SET Name = ?, Description = ?, Cost = ? WHERE PlatformID = ?");
                    ps.setString(1, newPlatformName);
                    ps.setString(2, newPlatformDesc);
                    ps.setInt(3, newPlatformCost);
                    ps.setInt(4, platform.getPlatformID());
                }
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Upload to the Database successful", "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }
    
    
    private boolean saveCompany(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            int counter = 0;
            IMP03_Company company = null;
            String newCompanyName = null;
            String newCompanyBranch = null;
            int newCompanySize = -1;
            double newCompanyRevenue = -1;
            String newCompanyComment = null;
            
            for(Object obj : myComponents){
                if(counter == 0 && obj instanceof IMP03_Company){
                    company = (IMP03_Company) obj;
                } else if(counter == 1 && obj instanceof JTextField /*&& isValid(obj)*/){
                    newCompanyName = ((JTextField)obj).getText();
                    
                    if(newCompanyName.equalsIgnoreCase(AdminToolView.EMPTY) || newCompanyName.equalsIgnoreCase("")){
                        throw new Exception("ERROR: Attemp to upload empty data to the database!");
                    }                    
                } else if(counter == 2 && obj instanceof JTextField && isValid(obj)){
                    newCompanyBranch = ((JTextField)obj).getText();
                } else if(counter == 3 && obj instanceof JTextField && isValid(obj)){
                    newCompanySize = Integer.valueOf(((JTextField)obj).getText());
                } else if(counter == 4 && obj instanceof JTextField && isValid(obj)){
                    newCompanyRevenue = Double.valueOf(((JTextField)obj).getText());
                } else if(counter == 5 && obj instanceof JTextField && isValid(obj)){
                    newCompanyComment = ((JTextField)obj).getText();
                }
                counter++;
            }
                        
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you want to update the Database?", "DB Upload", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(company.getCompanyID() == -1){
                    ps = dbConnection.prepareStatement("INSERT INTO company (Name, Branch, Size, Renvenue, Comment)"
                            + " VALUES (?, ?, ?, ?, ?)");
                    ps.setString(1, newCompanyName);
                    ps.setString(2, newCompanyBranch);
                    ps.setInt(3, newCompanySize);
                    ps.setDouble(4, newCompanyRevenue);
                    ps.setString(5, newCompanyComment);
                } else {
                    ps = dbConnection.prepareStatement("UPDATE company SET Name = ?, Branch = ?, Size = ?, Renvenue = ?, Comment = ? WHERE CompanyID = ?");
                    ps.setString(1, newCompanyName);
                    ps.setString(2, newCompanyBranch);
                    ps.setInt(3, newCompanySize);
                    ps.setDouble(4, newCompanyRevenue);
                    ps.setString(5, newCompanyComment);
                    ps.setInt(6, company.getCompanyID());
                }
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Upload to the Database successful", "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }    
    

    private boolean saveSkill(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            int counter = 0;
            IMP03_Skill skill = null;
            String newSkillName = null;
            String newSkillDesc = null;
            
            for(Object obj : myComponents){
                if(counter == 0 && obj instanceof IMP03_Skill){
                    skill = (IMP03_Skill) obj;
                } else if(counter == 1 && obj instanceof JTextField /*&& isValid(obj)*/){
                    newSkillName = ((JTextField)obj).getText();
                    
                    if(newSkillName.equalsIgnoreCase(AdminToolView.EMPTY) || newSkillName.equalsIgnoreCase("")){
                        throw new Exception("ERROR: Attemp to upload empty data to the database!");
                    }                    
                } else if(counter == 2 && obj instanceof JTextField && isValid(obj)){
                    newSkillDesc = ((JTextField)obj).getText();
                }
                counter++;
            }
            
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you want to update the Database?", "DB Upload", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(skill.getSkillID() == -1){
                    ps = dbConnection.prepareStatement("INSERT INTO skill (Name, Description)"
                            + " VALUES (?, ?)");
                    ps.setString(1, newSkillName);
                    ps.setString(2, newSkillDesc);
                } else {
                    ps = dbConnection.prepareStatement("UPDATE skill SET Name = ?, Description = ? WHERE SkillID = ?");
                    ps.setString(1, newSkillName);
                    ps.setString(2, newSkillDesc);
                    ps.setInt(3, skill.getSkillID());
                }
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Upload to the Database successful", "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }    


    private boolean saveVacancy(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            int counter = 0;
            IMP03_Vacancy vacancy = null;
            String newVacancyTitle = null;
            String newVacancyDesc = null;
            int newVacancyCompanyID = -1;
            String newVacancyPLZ = null;
            Date newVacancyStartDate = null;
            int newQualificationID = -1;
            int newExperience = -1;
            int newBudget = -1;
            int newAnualSalary = -1;
            boolean newFullTime = false;
            
            for(Object obj : myComponents){
                if(counter == 0 && obj instanceof IMP03_Vacancy){
                    vacancy = (IMP03_Vacancy) obj;
                } else if(counter == 1 && obj instanceof JTextField /*&& isValid(obj)*/){
                    newVacancyTitle = ((JTextField)obj).getText();
                    
                    if(newVacancyTitle.equalsIgnoreCase(AdminToolView.EMPTY) || newVacancyTitle.equalsIgnoreCase("")){
                        throw new Exception("ERROR: Attemp to upload empty data to the database!");
                    }                    
                } else if(counter == 2 && obj instanceof JTextField && isValid(obj)){
                    newVacancyDesc = ((JTextField)obj).getText();
                } else if(counter == 3 && obj instanceof JComboBox && isValid(obj)){
                    newVacancyCompanyID = ((IMP03_Company)((JComboBox)obj).getSelectedItem()).getCompanyID();
                } else if(counter == 4 && obj instanceof JComboBox && isValid(obj)){
                    newVacancyPLZ = ((IMP03_City)((JComboBox)obj).getSelectedItem()).getPLZ();
                } else if(counter == 5 && obj instanceof JFormattedTextField && isValid(obj)){
                    String date = ((JFormattedTextField)obj).getText();
                    Pattern myPattern = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}");
                    Matcher m = myPattern.matcher(date);
                    if(m.matches()){
                        newVacancyStartDate = Date.valueOf(date);
                    }
                } else if(counter == 6 && obj instanceof JComboBox && isValid(obj)){
                    newQualificationID = ((IMP03_Qualification)(((JComboBox)obj).getSelectedItem())).getQualificationID();
                } else if(counter == 7 && obj instanceof JTextField && isValid(obj)){
                    newExperience = Integer.valueOf(((JTextField)obj).getText());
                } else if(counter == 8 && obj instanceof JTextField && isValid(obj)){
                    newBudget = Integer.valueOf(((JTextField)obj).getText());
                } else if(counter == 9 && obj instanceof JTextField && isValid(obj)){
                    newAnualSalary = Integer.valueOf(((JTextField)obj).getText());
                } else if(counter == 10 && obj instanceof JCheckBox){
                    newFullTime = (boolean)((JCheckBox)obj).isSelected();
                }
                counter++;
            }
            
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you want to update the Database?", "DB Upload", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(vacancy.getVacancyID() == -1){
                    ps = dbConnection.prepareStatement("INSERT INTO vacancy "
                            + "(Title, Description, CompanyID, PLZ, StartDate, QualificationID, Budget, AnualSalary, FullTimePartTime, ExperienceInYears)"
                            + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                    ps.setString(1, newVacancyTitle);
                    ps.setString(2, newVacancyDesc);
                    ps.setInt(3, newVacancyCompanyID);
                    ps.setString(4, newVacancyPLZ);
                    ps.setDate(5, newVacancyStartDate);
                    ps.setInt(6, newQualificationID);
                    ps.setInt(7, newBudget);
                    ps.setInt(8, newAnualSalary);
                    ps.setBoolean(9, newFullTime);
                    ps.setInt(10, newExperience);

                } else {
                    ps = dbConnection.prepareStatement("UPDATE vacancy SET Title = ?, Description = ?, CompanyID = ?, PLZ = ?, StartDate = ?, "
                            + " QualificationID = ?, Budget = ?, AnualSalary = ?, FullTimePartTime = ?, ExperienceInYears = ? "
                            + " WHERE VacancyID = ?");
                    ps.setString(1, newVacancyTitle);
                    ps.setString(2, newVacancyDesc);
                    ps.setInt(3, newVacancyCompanyID);
                    ps.setString(4, newVacancyPLZ);
                    ps.setDate(5, newVacancyStartDate);
                    ps.setInt(6, newQualificationID);
                    ps.setInt(7, newBudget);
                    ps.setInt(8, newAnualSalary);
                    ps.setBoolean(9, newFullTime);
                    ps.setInt(10, newExperience);
                    ps.setInt(11, vacancy.getVacancyID());
                }

                ps.executeUpdate();

                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Upload to the Database successful", "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }

        
    private boolean removeVacancyFromPlatform(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Vacancy vacancy = null;
            IMP03_Platform platform = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Vacancy){
                    vacancy = (IMP03_Vacancy) obj;
                    break;
                } else if(obj instanceof IMP03_Platform){
                    platform = (IMP03_Platform) obj;
                    break;
                }
            }
            
            if(platform == null && vacancy == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }
            
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the platform-vacancy connection from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(vacancy != null){
                    JComboBox combo = (JComboBox) myComponents.get(12);
                    int platformID = ((IMP03_Platform)(combo.getSelectedItem())).getPlatformID();
                    ps = dbConnection.prepareStatement("DELETE FROM vacancy_platforms WHERE PlatformId = ? AND VacancyId = ?");
                    ps.setInt(1, platformID);
                    ps.setInt(2, vacancy.getVacancyID());
                } else if(platform != null){
                    JComboBox combo = (JComboBox) myComponents.get(3);
                    int vacancyID = ((IMP03_Vacancy)(combo.getSelectedItem())).getVacancyID();
                    ps = dbConnection.prepareStatement("DELETE FROM vacancy_platforms WHERE PlatformId = ? AND VacancyId = ?");
                    ps.setInt(1, platform.getPlatformID());
                    ps.setInt(2, vacancyID);
                }
                
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }


    private boolean removeSkillFromVacancy(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Vacancy vacancy = null;
            IMP03_Skill skill = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Vacancy){
                    vacancy = (IMP03_Vacancy) obj;
                    break;
                } else if(obj instanceof IMP03_Skill){
                    skill = (IMP03_Skill) obj;
                    break;
                }
            }
            
            if(skill == null && vacancy == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }
            
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the vacancy-skill connection from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(vacancy != null){
                    JComboBox combo = (JComboBox) myComponents.get(11);
                    int skillID = ((IMP03_Skill)combo.getSelectedItem()).getSkillID();
                    ps = dbConnection.prepareStatement("DELETE FROM vacancy_skills WHERE SkillId = ? AND VacancyId = ?");
                    ps.setInt(1, skillID);
                    ps.setInt(2, vacancy.getVacancyID());
                } else if(skill != null){
                    JComboBox combo = (JComboBox) myComponents.get(3);
                    int vacancyID = ((IMP03_Vacancy)combo.getSelectedItem()).getVacancyID();
                    ps = dbConnection.prepareStatement("DELETE FROM vacancy_skills WHERE SkillId = ? AND VacancyId = ?");
                    ps.setInt(1, skill.getSkillID());
                    ps.setInt(2, vacancyID);
                }
                
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }    
    
    
    private boolean removeSkillFromCandidate(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Candidate candidate = null;
            IMP03_Skill skill = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                    break;
                } else if(obj instanceof IMP03_Skill){
                    skill = (IMP03_Skill) obj;
                    break;
                }
            }
            
            if(skill == null && candidate == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }
            
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the candidate-skill connection from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(candidate != null){
                    JComboBox combo = (JComboBox) myComponents.get(7);
                    int skillID = ((IMP03_Skill)(combo.getSelectedItem())).getSkillID();
                    ps = dbConnection.prepareStatement("DELETE FROM candidate_skills WHERE SkillId = ? AND CandidateId = ?");
                    ps.setInt(1, skillID);
                    ps.setInt(2, candidate.getCandidateID());
                } else if(skill != null){
                    JComboBox combo = (JComboBox) myComponents.get(4);
                    int candidateID = ((IMP03_Candidate)combo.getSelectedItem()).getCandidateID();
                    ps = dbConnection.prepareStatement("DELETE FROM candidate_skills WHERE SkillId = ? AND CandidateId = ?");
                    ps.setInt(1, skill.getSkillID());
                    ps.setInt(2, candidateID);
                }
                
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    } 
    
   private boolean removePlatformFromCandidate(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Candidate candidate = null;
            IMP03_Platform platform = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                    break;
                } else if(obj instanceof IMP03_Platform){
                    platform = (IMP03_Platform) obj;
                    break;
                }
            }
            
            if(platform == null && candidate == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }
            
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the candidate-platform connection from the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(candidate != null){
                    JComboBox combo = (JComboBox) myComponents.get(8);
                    int platformID = ((IMP03_Platform)(combo.getSelectedItem())).getPlatformID();
                    ps = dbConnection.prepareStatement("DELETE FROM platform_candidates WHERE PlatformId = ? AND CandidateId = ?");
                    ps.setInt(1, platformID);
                    ps.setInt(2, candidate.getCandidateID());
                } else if(platform != null){
                    JComboBox combo = (JComboBox) myComponents.get(4);
                    int candidateID = ((IMP03_Candidate)combo.getSelectedItem()).getCandidateID();
                    ps = dbConnection.prepareStatement("DELETE FROM platform_candidates WHERE PlatformId = ? AND CandidateId = ?");
                    ps.setInt(1, platform.getPlatformID());
                    ps.setInt(2, candidateID);
                }
                
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }     

   
   private boolean removeExperienceFromCandidate(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Candidate candidate = null;
            IMP03_Experience experience = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                    break;
                } else if(obj instanceof IMP03_Experience){
                    experience = (IMP03_Experience) obj;
                    break;
                }
            }
            
            if(experience == null && candidate == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }
            
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you really want to remove the selected experience from the candidate in the Database?", "DB Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                JComboBox combo = (JComboBox) myComponents.get(9);
                int experienceID = ((IMP03_Experience)(combo.getSelectedItem())).getExperienceID();
                ps = dbConnection.prepareStatement("DELETE FROM experience WHERE ExperienceId = ? AND CandidateId = ?");
                ps.setInt(1, experienceID);
                ps.setInt(2, candidate.getCandidateID());
                
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Remove from Database successful", "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
    }     
   
    
    private boolean addVacancyToPlatform(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Vacancy vacancy = null;
            IMP03_Platform platform = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Vacancy){
                    vacancy = (IMP03_Vacancy) obj;
                    break;
                } else if(obj instanceof IMP03_Platform){
                    platform = (IMP03_Platform) obj;
                    break;
                }
            }
            
            if(platform == null && vacancy == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }

            //define the input dialog for definition of platform-vacancy-connections
            platformVacancyDialog = new JDialog();
            platformVacancyDialog.setModal(true);
            platformVacancyDialog.setTitle("Add vacancy to platform");
            
            GroupLayout layout2 = new GroupLayout(platformVacancyDialog.getContentPane());
            layout2.setAutoCreateGaps(true);
            platformVacancyDialog.setLayout(layout2);
            
            JLabel label1 = new JLabel();
            if(platform != null){
                label1.setText("Available vacancies");
                platformVacancyComboBox = new JComboBox(IMP03_Vacancy.getAllAvailableVacanciesFromDB(false).toArray());
            } else if(vacancy != null) {
                label1.setText("Available platforms");
                platformVacancyComboBox = new JComboBox(IMP03_Platform.getAllAvailablePlatformsFromDB(false).toArray());
            }
            JButton button3 = new JButton("Add vacancy to the platform");
            button3.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                        IMP03_Vacancy vacancy = null;
                        IMP03_Platform platform = null;
                        int selectedVacancyID = -1;
                        int selectedPlatformID = -1;
                        PreparedStatement ps = null;
                        ResultSet rs = null;

                        try {
                            for(Object obj : myComponents){
                                if(obj instanceof IMP03_Vacancy){
                                    vacancy = (IMP03_Vacancy) obj;
                                    selectedVacancyID = vacancy.getVacancyID();
                                    for(IMP03_Platform p : IMP03_Platform.getAllAvailablePlatformsFromDB(false)){
                                        if(p.getPlatformName().equalsIgnoreCase(platformVacancyComboBox.getSelectedItem().toString())){
                                            selectedPlatformID = p.getPlatformID();
                                            break;
                                        }
                                    }
                                    break;
                                } else if(obj instanceof IMP03_Platform){
                                    platform = (IMP03_Platform) obj;
                                    selectedPlatformID = platform.getPlatformID();
                                    for(IMP03_Vacancy v : IMP03_Vacancy.getAllAvailableVacanciesFromDB(false)){
                                        if(v.getVacancyTitle().equalsIgnoreCase(platformVacancyComboBox.getSelectedItem().toString())){
                                            selectedVacancyID = v.getVacancyID();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            
                            if(selectedPlatformID != -1 && selectedVacancyID != -1){
                                ps = AdminToolView.getDBConnection().prepareStatement("SELECT count(*) FROM vacancy_platforms WHERE VacancyID = ? AND PlatformID = ?");
                                ps.setInt(1, selectedVacancyID);
                                ps.setInt(2, selectedPlatformID);
                                rs = ps.executeQuery();
                                int resultCounter = 0;
                                while(rs.next()){
                                    resultCounter = rs.getInt(1);
                                }

                                ps.close();
                                ps = null;
                                rs.close();
                                rs = null;

                                if(resultCounter > 0){
                                    JOptionPane.showConfirmDialog(list_subSelection, "The vacancy-platform connection already exists", "Add vacancy to platform", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                                } else {
                                    ps = AdminToolView.getDBConnection().prepareStatement("INSERT INTO vacancy_platforms (VacancyID, PlatformID) VALUES(?, ?)");
                                    ps.setInt(1, selectedVacancyID);
                                    ps.setInt(2, selectedPlatformID);
                                    ps.executeUpdate();
                                    JOptionPane.showConfirmDialog(list_subSelection, "The vacancy-platform connection has been created sucessfully", "Add vacancy to platform", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                                }
                            }
                       } catch (Exception e1) {
                            e1.printStackTrace();
                        } finally {
                            try {
                                if(rs != null){
                                    rs.close();
                                }
                                if(ps != null){
                                    ps.close();
                                }
                            } catch (Exception e2) {
                            }
                        }
                    
                    //close dialog
                    platformVacancyDialog.dispose();
                }
            });
            
            // layout-definition
            layout2.setHorizontalGroup(
                layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout2.createSequentialGroup()
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(label1)
                        )
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(platformVacancyComboBox)
                        )
                    )
                    .addComponent(button3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );

            layout2.setVerticalGroup(
                layout2.createSequentialGroup()
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label1)
                        .addComponent(platformVacancyComboBox)
                    )
                    .addComponent(button3)
            );

            platformVacancyDialog.pack();
            platformVacancyDialog.setLocationRelativeTo(panel_parameters);
            platformVacancyDialog.setVisible(true);
            
            returnValue = true;
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }
    
    private boolean addSkillToVacancy(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Vacancy vacancy = null;
            IMP03_Skill skill = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Vacancy){
                    vacancy = (IMP03_Vacancy) obj;
                    break;
                } else if(obj instanceof IMP03_Skill){
                    skill = (IMP03_Skill) obj;
                    break;
                }
            }
            
            if(skill == null && vacancy == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }

            //define the input dialog for definition of platform-vacancy-connections
            skillVacancyDialog = new JDialog();
            skillVacancyDialog.setModal(true);
            skillVacancyDialog.setTitle("Add skill to vacancy");
            
            GroupLayout layout2 = new GroupLayout(skillVacancyDialog.getContentPane());
            layout2.setAutoCreateGaps(true);
            skillVacancyDialog.setLayout(layout2);
            
            JLabel label1 = new JLabel();
            JLabel label2 = new JLabel("SkillLevel");
            if(skill != null){
                label1.setText("Available vacancies");
                skillVacancyComboBox = new JComboBox(IMP03_Vacancy.getAllAvailableVacanciesFromDB(false).toArray());
            } else if(vacancy != null) {
                label1.setText("Available platforms");
                skillVacancyComboBox = new JComboBox(IMP03_Skill.getAllAvailableSkillsFromDB(false).toArray());
            }
            skillLevelComboBox = new JComboBox(new Integer[]{1,2,3});
            JButton button3 = new JButton("Add skill to vacancy");
            button3.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                        IMP03_Vacancy vacancy = null;
                        IMP03_Skill skill = null;
                        int selectedVacancyID = -1;
                        int selectedSkillID = -1;
                        PreparedStatement ps = null;
                        ResultSet rs = null;

                        try {
                            for(Object obj : myComponents){
                                if(obj instanceof IMP03_Vacancy){
                                    vacancy = (IMP03_Vacancy) obj;
                                    selectedVacancyID = vacancy.getVacancyID();
                                    for(IMP03_Skill s : IMP03_Skill.getAllAvailableSkillsFromDB(false)){
                                        if(s.getSkillName().equalsIgnoreCase(skillVacancyComboBox.getSelectedItem().toString())){
                                            selectedSkillID = s.getSkillID();
                                            break;
                                        }
                                    }
                                    break;
                                } else if(obj instanceof IMP03_Skill){
                                    skill = (IMP03_Skill) obj;
                                    selectedSkillID = skill.getSkillID();
                                    for(IMP03_Vacancy v : IMP03_Vacancy.getAllAvailableVacanciesFromDB(false)){
                                        if(v.getVacancyTitle().equalsIgnoreCase(skillVacancyComboBox.getSelectedItem().toString())){
                                            selectedVacancyID = v.getVacancyID();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            
                            if(selectedSkillID != -1 && selectedVacancyID != -1){
                                ps = AdminToolView.getDBConnection().prepareStatement("SELECT count(*) FROM vacancy_skills WHERE VacancyID = ? AND SkillID = ?");
                                ps.setInt(1, selectedVacancyID);
                                ps.setInt(2, selectedSkillID);
                                rs = ps.executeQuery();
                                int resultCounter = 0;
                                while(rs.next()){
                                    resultCounter = rs.getInt(1);
                                }

                                ps.close();
                                ps = null;
                                rs.close();
                                rs = null;

                                if(resultCounter > 0){
                                    JOptionPane.showConfirmDialog(list_subSelection, "The vacancy-skill connection already exists", "Add skill to vacancy", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                                } else {
                                    ps = AdminToolView.getDBConnection().prepareStatement("INSERT INTO vacancy_skills (VacancyID, SkillID, SkillLevel) VALUES(?, ?, ?)");
                                    ps.setInt(1, selectedVacancyID);
                                    ps.setInt(2, selectedSkillID);
                                    ps.setInt(3, Integer.valueOf(skillLevelComboBox.getSelectedItem().toString()));
                                    ps.executeUpdate();
                                    JOptionPane.showConfirmDialog(list_subSelection, "The vacancy-skill connection has been created sucessfully", "Add skill to vacancy", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                                }
                            }
                       } catch (Exception e1) {
                            e1.printStackTrace();
                        } finally {
                            try {
                                if(rs != null){
                                    rs.close();
                                }
                                if(ps != null){
                                    ps.close();
                                }
                            } catch (Exception e2) {
                            }
                        }
                    
                    //close dialog
                    skillVacancyDialog.dispose();
                }
            });
            
            // layout-definition
            layout2.setHorizontalGroup(
                layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout2.createSequentialGroup()
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(label1)
                            .addComponent(label2)
                        )
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(skillVacancyComboBox)
                            .addComponent(skillLevelComboBox)
                        )
                    )
                    .addComponent(button3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );

            layout2.setVerticalGroup(
                layout2.createSequentialGroup()
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label1)
                        .addComponent(skillVacancyComboBox)
                    )
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label2)
                        .addComponent(skillLevelComboBox)
                    )
                    .addComponent(button3)
            );

            skillVacancyDialog.pack();
            skillVacancyDialog.setLocationRelativeTo(panel_parameters);
            skillVacancyDialog.setVisible(true);
            
            returnValue = true;
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }    

    
   private boolean addSkillToCandidate(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Candidate candidate = null;
            IMP03_Skill skill = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                    break;
                } else if(obj instanceof IMP03_Skill){
                    skill = (IMP03_Skill) obj;
                    break;
                }
            }
            
            if(skill == null && candidate == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }

            //define the input dialog for definition of platform-vacancy-connections
            skillCandidateDialog = new JDialog();
            skillCandidateDialog.setModal(true);
            skillCandidateDialog.setTitle("Add skill to candidate");
            
            GroupLayout layout2 = new GroupLayout(skillCandidateDialog.getContentPane());
            layout2.setAutoCreateGaps(true);
            skillCandidateDialog.setLayout(layout2);
            
            JLabel label1 = new JLabel();
            JLabel label2 = new JLabel("SkillLevel ");
            if(skill != null){
                label1.setText("Available candidate");
                skillCandidateComboBox = new JComboBox(IMP03_Candidate.getAllAvailableCandidatesFromDB(true).toArray());
            } else if(candidate != null) {
                label1.setText("Available skill");
                skillCandidateComboBox = new JComboBox(IMP03_Skill.getAllAvailableSkillsFromDB(false).toArray());
            }
            skillLevelComboBox = new JComboBox(new Integer[]{1,2,3});
            JButton button3 = new JButton("Add skill to candidate");
            button3.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                        IMP03_Candidate candidate = null;
                        IMP03_Skill skill = null;
                        int selectedCandidateID = -1;
                        int selectedSkillID = -1;
                        PreparedStatement ps = null;
                        ResultSet rs = null;

                        try {
                            for(Object obj : myComponents){
                                if(obj instanceof IMP03_Candidate){
                                    candidate = (IMP03_Candidate) obj;
                                    selectedCandidateID = candidate.getCandidateID();
                                    for(IMP03_Skill s : IMP03_Skill.getAllAvailableSkillsFromDB(false)){
                                        if(s.getSkillID()  == ((IMP03_Skill)skillCandidateComboBox.getSelectedItem()).getSkillID()){
                                            selectedSkillID = s.getSkillID();
                                            break;
                                        }
                                    }
                                    break;
                                } else if(obj instanceof IMP03_Skill){
                                    skill = (IMP03_Skill) obj;
                                    selectedSkillID = skill.getSkillID();
                                    for(IMP03_Candidate c : IMP03_Candidate.getAllAvailableCandidatesFromDB(false)){
                                        if(c.getCandidateID() == ((IMP03_Candidate)skillCandidateComboBox.getSelectedItem()).getCandidateID()){
                                            selectedCandidateID = c.getCandidateID();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            
                            if(selectedSkillID != -1 && selectedCandidateID != -1){
                                ps = AdminToolView.getDBConnection().prepareStatement("SELECT count(*) FROM candidate_skills WHERE CandidateID = ? AND SkillID = ?");
                                ps.setInt(1, selectedCandidateID);
                                ps.setInt(2, selectedSkillID);
                                rs = ps.executeQuery();
                                int resultCounter = 0;
                                while(rs.next()){
                                    resultCounter = rs.getInt(1);
                                }

                                ps.close();
                                ps = null;
                                rs.close();
                                rs = null;

                                if(resultCounter > 0){
                                    JOptionPane.showConfirmDialog(list_subSelection, "The candidate-skill connection already exists", "Add skill to candidate", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                                } else {
                                    ps = AdminToolView.getDBConnection().prepareStatement("INSERT INTO candidate_skills (CandidateID, SkillID, SkillLevel) VALUES(?, ?, ?)");
                                    ps.setInt(1, selectedCandidateID);
                                    ps.setInt(2, selectedSkillID);
                                    ps.setInt(3, Integer.valueOf(skillLevelComboBox.getSelectedItem().toString()));
                                    ps.executeUpdate();
                                    JOptionPane.showConfirmDialog(list_subSelection, "The candidate-skill connection has been created sucessfully", "Add skill to vacancy", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                                }
                            }
                       } catch (Exception e1) {
                            e1.printStackTrace();
                        } finally {
                            try {
                                if(rs != null){
                                    rs.close();
                                }
                                if(ps != null){
                                    ps.close();
                                }
                            } catch (Exception e2) {
                            }
                        }
                    
                    //close dialog
                    skillCandidateDialog.dispose();
                }
            });
            
            // layout-definition
            layout2.setHorizontalGroup(
                layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout2.createSequentialGroup()
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(label1)
                            .addComponent(label2)
                        )
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(skillCandidateComboBox)
                            .addComponent(skillLevelComboBox)
                        )
                    )
                    .addComponent(button3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );

            layout2.setVerticalGroup(
                layout2.createSequentialGroup()
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label1)
                        .addComponent(skillCandidateComboBox)
                    )
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label2)
                        .addComponent(skillLevelComboBox)
                    )
                    .addComponent(button3)
            );

            skillCandidateDialog.pack();
            skillCandidateDialog.setLocationRelativeTo(panel_parameters);
            skillCandidateDialog.setVisible(true);
            
            returnValue = true;
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }       
    
    
    private boolean addPlatformToCandidate(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Candidate candidate = null;
            IMP03_Platform platform = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                    break;
                } else if(obj instanceof IMP03_Platform){
                    platform = (IMP03_Platform) obj;
                    break;
                }
            }
            
            if(platform == null && candidate == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }

            //define the input dialog for definition of platform-vacancy-connections
            platformCandidateDialog = new JDialog();
            platformCandidateDialog.setModal(true);
            platformCandidateDialog.setTitle("Add candidate to platform");
            
            GroupLayout layout2 = new GroupLayout(platformCandidateDialog.getContentPane());
            layout2.setAutoCreateGaps(true);
            platformCandidateDialog.setLayout(layout2);
            
            JLabel label1 = new JLabel();
            if(platform != null){
                label1.setText("Available candidates");
                platformCandidateComboBox = new JComboBox(IMP03_Candidate.getAllAvailableCandidatesFromDB(true).toArray());
            } else if(candidate != null) {
                label1.setText("Available platforms");
                platformCandidateComboBox = new JComboBox(IMP03_Platform.getAllAvailablePlatformsFromDB(true).toArray());
            }
            JButton button3 = new JButton("Add candidate to platform");
            button3.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                        IMP03_Candidate candidate = null;
                        IMP03_Platform platform = null;
                        int selectedCandidateID = -1;
                        int selectedPlatformID = -1;
                        PreparedStatement ps = null;
                        ResultSet rs = null;

                        try {
                            for(Object obj : myComponents){
                                if(obj instanceof IMP03_Candidate){
                                    candidate = (IMP03_Candidate) obj;
                                    selectedCandidateID = candidate.getCandidateID();
                                    for(IMP03_Platform p : IMP03_Platform.getAllAvailablePlatformsFromDB(false)){
                                        if(p.getPlatformID()  == ((IMP03_Platform)platformCandidateComboBox.getSelectedItem()).getPlatformID()){
                                            selectedPlatformID = p.getPlatformID();
                                            break;
                                        }
                                    }
                                    break;
                                } else if(obj instanceof IMP03_Platform){
                                    platform = (IMP03_Platform) obj;
                                    selectedPlatformID = platform.getPlatformID();
                                    for(IMP03_Candidate c : IMP03_Candidate.getAllAvailableCandidatesFromDB(false)){
                                        if(c.getCandidateID() == ((IMP03_Candidate)platformCandidateComboBox.getSelectedItem()).getCandidateID()){
                                            selectedCandidateID = c.getCandidateID();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            
                            if(selectedPlatformID != -1 && selectedCandidateID != -1){
                                ps = AdminToolView.getDBConnection().prepareStatement("SELECT count(*) FROM platform_candidates WHERE CandidateID = ? AND PlatformID = ?");
                                ps.setInt(1, selectedCandidateID);
                                ps.setInt(2, selectedPlatformID);
                                rs = ps.executeQuery();
                                int resultCounter = 0;
                                while(rs.next()){
                                    resultCounter = rs.getInt(1);
                                }

                                ps.close();
                                ps = null;
                                rs.close();
                                rs = null;

                                if(resultCounter > 0){
                                    JOptionPane.showConfirmDialog(list_subSelection, "The platform-candidate connection already exists", "Add skill to candidate", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                                } else {
                                    ps = AdminToolView.getDBConnection().prepareStatement("INSERT INTO platform_candidates (CandidateID, PlatformID) VALUES(?, ?)");
                                    ps.setInt(1, selectedCandidateID);
                                    ps.setInt(2, selectedPlatformID);
                                    ps.executeUpdate();
                                    JOptionPane.showConfirmDialog(list_subSelection, "The platform-candidate connection has been created sucessfully", "Add skill to vacancy", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                                }
                            }
                       } catch (Exception e1) {
                            e1.printStackTrace();
                        } finally {
                            try {
                                if(rs != null){
                                    rs.close();
                                }
                                if(ps != null){
                                    ps.close();
                                }
                            } catch (Exception e2) {
                            }
                        }
                    
                    //close dialog
                    platformCandidateDialog.dispose();
                }
            });
            
            // layout-definition
            layout2.setHorizontalGroup(
                layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout2.createSequentialGroup()
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(label1)
                        )
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(platformCandidateComboBox)
                        )
                    )
                    .addComponent(button3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );

            layout2.setVerticalGroup(
                layout2.createSequentialGroup()
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label1)
                        .addComponent(platformCandidateComboBox)
                    )
                    .addComponent(button3)
            );

            platformCandidateDialog.pack();
            platformCandidateDialog.setLocationRelativeTo(panel_parameters);
            platformCandidateDialog.setVisible(true);
            
            returnValue = true;
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }    


    private boolean addExperienceToCandidate(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Candidate candidate = null;
            IMP03_Experience experience = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                    break;
                } else if(obj instanceof IMP03_Experience){
                    experience = (IMP03_Experience) obj;
                    break;
                }
            }
            
            if(experience == null && candidate == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }

            //define the input dialog for definition of platform-vacancy-connections
            candidateExperienceDialog = new JDialog();
            candidateExperienceDialog.setModal(true);
            candidateExperienceDialog.setTitle("Add experience to candidate");
            
            GroupLayout layout2 = new GroupLayout(candidateExperienceDialog.getContentPane());
            layout2.setAutoCreateGaps(true);
            candidateExperienceDialog.setLayout(layout2);
            
            JLabel label1 = new JLabel("Company");
            JLabel label2 = new JLabel("Role");
            JLabel label3 = new JLabel("Duration [years]");

            experience_CompanyName = new JTextField();
            experience_RoleDesc = new JTextField();
            experience_DurationInYears = new JTextField();
            
            JButton button4 = new JButton("Add experience to candidate");
            button4.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                        IMP03_Candidate candidate = null;
                        int selectedCandidateID = -1;
                        PreparedStatement ps = null;
                        ResultSet rs = null;

                        try {
                            for(Object obj : myComponents){
                                if(obj instanceof IMP03_Candidate){
                                    candidate = (IMP03_Candidate) obj;
                                    selectedCandidateID = candidate.getCandidateID();
                                    break;
                                }
                            }
                            
                            if(selectedCandidateID != -1){
                                ps = AdminToolView.getDBConnection().prepareStatement("INSERT INTO experience (CandidateID, CompanyName, RoleDesc, DurationInYears) VALUES(?, ?, ?, ?)");
                                ps.setInt(1, selectedCandidateID);
                                ps.setString(2, experience_CompanyName.getText());
                                ps.setString(3, experience_RoleDesc.getText());
                                ps.setInt(4, Integer.valueOf(experience_DurationInYears.getText()));
                                ps.executeUpdate();
                                JOptionPane.showConfirmDialog(list_subSelection, "The experience has sucessfully been added to the candidate", "Add experience to candidate", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
                            }
                       } catch (Exception e1) {
                            JOptionPane.showConfirmDialog(list_subSelection, e1.getMessage(), "DB DELETE ERROR", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
                            e1.printStackTrace();
                        } finally {
                            try {
                                if(rs != null){
                                    rs.close();
                                }
                                if(ps != null){
                                    ps.close();
                                }
                            } catch (Exception e2) {
                            }
                        }
                    
                    //close dialog
                    candidateExperienceDialog.dispose();
                }
            });
            
            // layout-definition
            layout2.setHorizontalGroup(
                layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout2.createSequentialGroup()
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(label1)
                            .addComponent(label2)
                            .addComponent(label3)
                        )
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(experience_CompanyName)
                            .addComponent(experience_RoleDesc)
                            .addComponent(experience_DurationInYears)
                        )
                    )
                    .addComponent(button4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );

            layout2.setVerticalGroup(
                layout2.createSequentialGroup()
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label1)
                        .addComponent(experience_CompanyName)
                    )
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label2)
                        .addComponent(experience_RoleDesc)
                    )
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label3)
                        .addComponent(experience_DurationInYears)
                    )
                    .addComponent(button4)
            );

            candidateExperienceDialog.pack();
            candidateExperienceDialog.setLocationRelativeTo(panel_parameters);
            candidateExperienceDialog.setVisible(true);
            
            returnValue = true;
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }    
    
    
   private boolean isValid(Object o){
       boolean retval = true;
       
       if(o instanceof JTextArea){
           if(((JTextArea)o).getText().equalsIgnoreCase(AdminToolView.EMPTY) || ((JTextArea)o).getText().equalsIgnoreCase("")){
               retval = false;
           }
       } else if(o instanceof JTextField){
           if(((JTextField)o).getText().equalsIgnoreCase(AdminToolView.EMPTY) || ((JTextField)o).getText().equalsIgnoreCase("")){
               retval = false;
           }
       } else if(o instanceof JComboBox){
           if(((JComboBox)o).getSelectedItem() == null || ((JComboBox)o).getSelectedItem().toString().equalsIgnoreCase(AdminToolView.EMPTY) || ((JComboBox)o).getSelectedItem().toString().equalsIgnoreCase("")){
               retval = false;
           }
       } else if(o instanceof JFormattedTextField){
           if(((JFormattedTextField)o).getText().equalsIgnoreCase(AdminToolView.EMPTY) || ((JFormattedTextField)o).getText().equalsIgnoreCase("")){
               retval = false;
           }
       }         
       
       return retval;
   }
   
   private void updateCandidateVacancyMatch(){
        PreparedStatement ps = null;
        IMP03_Candidate candidate = null;
        IMP03_Vacancy vacancy = null;
        ArrayList<Object> affectecObjects = new ArrayList<Object>();

        try {
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Candidate){
                    candidate = (IMP03_Candidate) obj;
                    candidate = IMP03_Candidate.getSpecificCandidateFromDB(candidate.getCandidateID());
                    break;
                } else if(obj instanceof IMP03_Vacancy){
                    vacancy = (IMP03_Vacancy) obj;
                    vacancy = IMP03_Vacancy.getSpecificVacancyFromDB(vacancy.getVacancyID());
                    break;
                }
            }

            if(candidate != null){
                affectecObjects.addAll(IMP03_Vacancy.getAllAvailableVacanciesFromDB(false));
            } else if(vacancy != null){
                affectecObjects.addAll(IMP03_Candidate.getAllAvailableCandidatesFromDB(false));
            }
            
            for (Object o : affectecObjects) {
                if(candidate != null){
                    vacancy = (IMP03_Vacancy) o;
                } else if(vacancy != null){
                    candidate = (IMP03_Candidate) o;
                }
                
                if(candidate == null || vacancy == null){
                    throw new Exception("Vacancy / Candidate could not be identified");
                }

                //Remove instances
                ps = dbConnection.prepareStatement("DELETE FROM vacancy_candidate WHERE CandidateID = ? AND VacancyID = ?");
                ps.setInt(1, candidate.getCandidateID());
                ps.setInt(2, vacancy.getVacancyID());
                ps.executeUpdate();
                ps.close();
                
                //generate instances
                int matchRating = new MatchRatingCalculator(candidate, vacancy).getCandidateVacancyMatch();
                
                System.out.println("matchRating for candidate " + candidate.getFirstName() + " " + 
                        candidate.getLastName() + " for the vacancy " + vacancy.getVacancyTitle() + " = " + matchRating);
                
                ps = dbConnection.prepareStatement("INSERT INTO vacancy_candidate (MatchRating, CandidateID, VacancyID) VALUES (?, ?, ?)");
                ps.setInt(1, matchRating);
                ps.setInt(2, candidate.getCandidateID());
                ps.setInt(3, vacancy.getVacancyID());
                ps.executeUpdate();
            }                
       } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "Update CandidateVacancyMatch", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
   }
  
   private boolean saveMessage(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            int counter = 0;
            IMP03_Message message = null;
            String newSubject = null;
            String newContent = null;
            int newCandidateID = -1;
            
            for(Object obj : myComponents){
                if(counter == 0 && obj instanceof IMP03_Message){
                    message = (IMP03_Message) obj;
                } else if(counter == 1 && obj instanceof JTextField /*&& isValid(obj)*/){
                    newSubject = ((JTextField)obj).getText();
                    
                    if(newSubject.equalsIgnoreCase(AdminToolView.EMPTY) || newSubject.equalsIgnoreCase("")){
                        throw new Exception("ERROR: Attemp to upload empty data to the database!");
                    }
                } else if(counter == 2 && obj instanceof JTextArea && isValid(obj)){
                    newContent = ((JTextArea)obj).getText();
                } else if(counter == 3 && obj instanceof JComboBox && isValid(obj)){
                    newCandidateID = ((IMP03_Candidate)(((JComboBox)obj).getSelectedItem())).getCandidateID();
                }
                counter++;
            }
                        
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you want to update the Database?", "DB Upload", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(message.getMessageID() == -1){
                    ps = dbConnection.prepareStatement("INSERT INTO message (CandidateID, Subject, Content) VALUES (?, ?, ?)");
                    ps.setInt(1, newCandidateID);
                    ps.setString(2, newSubject);
                    ps.setString(3, newContent);
                } else {
                    ps = dbConnection.prepareStatement("UPDATE message SET CandidateID = ?, Subject = ?, Content = ? WHERE MessageID = ?");
                    ps.setInt(1, newCandidateID);
                    ps.setString(2, newSubject);
                    ps.setString(3, newContent);
                    ps.setInt(4, message.getMessageID());
                }
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Upload to the Database successful", "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }

   
   private boolean saveTip(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            int counter = 0;
            IMP03_Tip tip = null;
            int stageID = -1;
            int costs = -1;
            String tipText = "";
            
            for(Object obj : myComponents){
                if(counter == 0 && obj instanceof IMP03_Tip){
                    tip = (IMP03_Tip) obj;
                } else if(counter == 1 && obj instanceof JTextField /*&& isValid(obj)*/){
                    stageID = Integer.parseInt(((JTextField)obj).getText());
                    
                    if(stageID == -1){
                        throw new Exception("ERROR: Attemp to upload empty data to the database!");
                    }
                } else if(counter == 2 && obj instanceof JTextField && isValid(obj)){
                    costs = Integer.parseInt(((JTextField)obj).getText());
                } else if(counter == 3 && obj instanceof JTextArea && isValid(obj)){
                    tipText = ((JTextArea)obj).getText();
                }
                counter++;
            }
                        
            int result = JOptionPane.showConfirmDialog(list_subSelection, "Do you want to update the Database?", "DB Upload", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(result == 0){
                if(tip.getTipID() == -1){
                    ps = dbConnection.prepareStatement("INSERT INTO tip (StageID, Costs, Text) VALUES (?, ?, ?)");
                    ps.setInt(1, stageID);
                    ps.setInt(2, costs);
                    ps.setString(3, tipText);
                } else {
                    ps = dbConnection.prepareStatement("UPDATE tip SET StageID = ?, Costs = ?, Text = ? WHERE TipID = ?");
                    ps.setInt(1, stageID);
                    ps.setInt(2, costs);
                    ps.setString(3, tipText);
                    ps.setInt(4, tip.getTipID());
                }
                ps.executeUpdate();
                
                returnValue = true;
                JOptionPane.showConfirmDialog(list_subSelection, "Upload to the Database successful", "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Upload", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }   
   
   private boolean addCandidateToMessage(){
        PreparedStatement ps = null;
        boolean returnValue = false;

        try {
            IMP03_Message message = null;
            
            for(Object obj : myComponents){
                if(obj instanceof IMP03_Message){
                    message = (IMP03_Message) obj;
                    break;
                }
            }
            
            if(message == null ){
                throw new Exception("VALUES COULD NOT BE IDENTIFIED!");
            }

            //define the input dialog for definition of platform-vacancy-connections
            messageCandidateDialog = new JDialog();
            messageCandidateDialog.setModal(true);
            messageCandidateDialog.setTitle("Add candidate to the message");
            
            GroupLayout layout2 = new GroupLayout(messageCandidateDialog.getContentPane());
            layout2.setAutoCreateGaps(true);
            messageCandidateDialog.setLayout(layout2);
            
            JLabel label1 = new JLabel();
            label1.setText("Available candidate");
            tmpMessageCandidateComboBox = new JComboBox(IMP03_Candidate.getAllAvailableCandidatesFromDB(true).toArray());

            JButton button3 = new JButton("Add candidate to the message");
            button3.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    
                    messageCandidateName.removeAllItems();
                    messageCandidateName.addItem((tmpMessageCandidateComboBox.getSelectedItem()));
                    
                    //close dialog
                    messageCandidateDialog.dispose();
                }
            });
            
            // layout-definition
            layout2.setHorizontalGroup(
                layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout2.createSequentialGroup()
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(label1)
                        )
                        .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(tmpMessageCandidateComboBox)
                        )
                    )
                    .addComponent(button3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );

            layout2.setVerticalGroup(
                layout2.createSequentialGroup()
                    .addGroup(layout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label1)
                        .addComponent(tmpMessageCandidateComboBox)
                    )
                    .addComponent(button3)
            );

            messageCandidateDialog.pack();
            messageCandidateDialog.setLocationRelativeTo(panel_parameters);
            messageCandidateDialog.setVisible(true);
            
            returnValue = true;
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(list_subSelection, e.getMessage(), "DB Delete", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return returnValue;
   }   
   
}